<?php
namespace App\Admin\Extensions;
use Encore\Admin\Admin;

class BlackAdd
{
    protected $orderid;

    public function __construct($orderid)
    {
        $this->orderid = $orderid;
    }

    protected function script()
    {
        return <<<SCRIPT
layui.use('layer', function(){
        var layer = layui.layer;
        $('.black').click(function () {
           var that = this;
           layer.confirm('确定加入黑名单?', {icon: 3, title:'提示'}, function(index){
               var orderid = $(that).attr('data-orderid');
               $.ajax({
                    url: '/admin/common/black/add?oid='+orderid,
                    type: 'post',
                   success: function (res) {
                       if(res.code == 0) {
                           layer.msg(res.text)
                           $(that).prop('disabled', true);
                           layer.close(index);
                       }else{
                           layer.msg(res.text);
                       }
                   }
               })
           });
       });
});

SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());
        return "&nbsp;<a href='javascript:void(0);'><button data-orderid='{$this->orderid}' class='black layui-btn layui-bg-black layui-btn-xs'>黑</button></a>";
    }

    public function __toString()
    {
        return $this->render();
    }
}
